package cn.wildfire.chat.kit.widget;

import android.content.Context;
import android.util.AttributeSet;
import android.view.MotionEvent;

import androidx.annotation.NonNull;
import androidx.annotation.Nullable;
import androidx.viewpager.widget.ViewPager;

/**
 * modify by HEKE , 2019/9/7 12:06 TODO 添加不可左右滑动设置开关
 */
public class ViewPagerFixed extends ViewPager {

    private boolean canScroll = true;

    private OnCildViewTouchEventListener onCildViewTouchEventListener;

    public ViewPagerFixed(@NonNull Context context) {
        super(context);
    }

    public ViewPagerFixed(@NonNull Context context, @Nullable AttributeSet attrs) {
        super(context, attrs);
    }

    public void setCanScroll(boolean canScroll) {
        this.canScroll = canScroll;
    }

    public boolean isCanScroll() {
        return canScroll;
    }

    public void setOnCildViewTouchEventListener(OnCildViewTouchEventListener onCildViewTouchEventListener) {
        this.onCildViewTouchEventListener = onCildViewTouchEventListener;
    }

    @Override
    public boolean onTouchEvent(MotionEvent arg0) {
        if (!canScroll){
            return false;
        }else{
            return super.onTouchEvent(arg0);
        }
    }

    @Override
    public boolean onInterceptTouchEvent(MotionEvent arg0) {
        if (!canScroll){
            return false;
        }else{
            return super.onInterceptTouchEvent(arg0);
        }
    }

    /**
     * Create by HEKE, 2019/9/7 12:10
     * TODO 为触摸事件透传回调接口
     */
    public interface OnCildViewTouchEventListener {
        void dispathTouchEvent(MotionEvent event);
    }

}
